<template>
  <div id="updateDialog">
    <el-dialog class="box" title="还原测点" :visible.sync="updateDialogShow" :before-close="handleClose">
      <div class="topSearch">
        <el-row>
          <el-col :span="6" style="margin-left: 20px">
            <div class="grid-content bg-purple">已删除测点列表</div>
          </el-col>
          <el-col :span="12" style="float: right; margin-right: 20px" >
            <div class="grid-content bg-purple-light ">
              <el-input placeholder="" v-model="returnPoint.data.condition.search"></el-input>
              <i class="el-icon-search search" @click="queryPointData"></i>
            </div>
          </el-col>
        </el-row>

      </div>
      <div class="content">
        <el-table
          :data="pointData"
          border
          stripe border fit highlight-current-row
          style="width: 95.8%;height:230px; margin-left: 9px "
          :header-cell-style="{background:'#D8DEE8',height: '20px',padding:'5px 0px'}"
          @selection-change="moreDelete"
          height="200px"
        >
          <el-table-column type="selection" align="center" width="40" @selection-change="moreDelete"></el-table-column>
          <el-table-column
            v-for="(column, index) in cols"
            :prop="column.prop"
            :label="column.label"
            :key="index"
            :width="column.width"
            :sortable="column.sortable"
          >
          </el-table-column>
        </el-table>
        <div class="pagination-container footerPage">
          <el-pagination
            @current-change="CurrentChange"
            @size-change="SizeChange"
            :page-sizes="[5, 10, 20, 50]"
            background layout="total, sizes, prev, pager, next"
            :total="total">
          </el-pagination>
        </div>
      </div>
        <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="queryReductionPoint">还原</el-button>
        <el-button type="info" @click="handleClose" >取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import axios from 'axios'
  export default {
    props: {
      Cid: '',
      Pid: ''
    },
    components: {
    },
    data() {
      return {
        pointData: [],
        restart: '更新',
        // 获取还原测点
        returnPoint: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'object_station_gethide',
          data: {
            condition: {
              pid: 'default',
              cid: 'plc0003',
              search: ''
            },
            page: {
              page_size: '10',
              page_number: '1'
            }
          }
        },
        // 还原测点
        reductionPoint: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'object_station_restore',
          pid: this.$route.query.pid,
          cid: '',
          ids: []
        },
        updateDialogFalse: false,
        cols: [
          { prop: 'oid', label: '测点编号', width: '150px', sortable: true },
          { prop: 'name', label: '测点名称', width: '150px', sortable: true },
          { prop: 'type', label: '测点类型', width: '150px', sortable: true },
          { prop: 'rates', label: '比率' }
        ],
        tableData: [],
        total: 0
      }
    },
    created() {
      this.updateDialogShow = true
    },
    mounted() {
      this.queryPointData()
    },
    methods: {
      // 查询测点信息
      queryPointData() {
        this.returnPoint.data.condition.pid = this.Pid
        this.returnPoint.data.condition.cid = this.Cid
        // this.returnPoint.data.condition.search = this.inputSearch
        axios.post('/project', this.returnPoint, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.pointData = res.data.data.items
          this.total = parseInt(res.data.data.page.total)
        })
          .catch(function(error) {
            console.log(error)
          })
      },
      // 当前页
      CurrentChange(val) {
        this.returnPoint.data.page.page_number = (val) + ''
        this.queryPointData()
      },
      // 每页显示多少条
      SizeChange(pageSize) {
        this.returnPoint.data.page.page_size = (pageSize) + ''
        this.queryPointData()
      },
      // 获取多选项
      moreDelete(val) {
        this.multipleSelection = val
        var deletemoreid = []
        for (var i = 0; i < this.multipleSelection.length; i++) {
          deletemoreid.push(this.multipleSelection[i].oid)
        }
        this.reductionPoint.ids = deletemoreid
      },
      // 还原测点
      queryReductionPoint() {
        this.reductionPoint.cid = this.Cid
        axios.post('/project', this.reductionPoint, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.handleClose()
          this.restar()
          this.$message({
            type: 'success',
            message: '还原成功'
          })
        })
          .catch(function(error) {
            this.$message({
              type: 'info',
              message: error
            })
          })
      },
      // 刷新列表
      restar() {
        this.$emit('diaStatus', this.restart)
      },
      // 子组件传值
      handleClose() {
        const dialogShow = this.updateDialogFalse // 所需要传的值
        this.$emit('giveFalse', dialogShow) // 传值的参数
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /*****************第一层弹窗*****************/
  .topSearch{
    width: 717px;
    height: 50px;
    margin-left: 10px;
    background-color: #d3dce6;
    line-height: 50px;
  }
  .search{
    margin-top: -31px;
    position: absolute;
    margin-left: 327px;
    color: #25B6C7;
    cursor: pointer;
  }
  /*****************第一层弹窗*****************/
  /deep/ .box > .el-dialog{
    width: 760px;
    height: 450px;
    /*max-height: 450px;*/
    // overflow: auto;
    margin-top: 20vh !important;
    border-radius: 4px;
  }
  /deep/ .gutter {
    background-color: #D8DEE8;
  }
  /*****************第一层弹窗头部*****************/
  /deep/ .box > .el-dialog > .el-dialog__header{
    width: 760px;
    height: 39px;
    line-height: 43px;
    padding: 0;
    text-indent: 20px;
    font-weight: bolder;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    background-color: #e3e6ee;
  }
  /deep/ .box > .el-dialog > .el-dialog__header > .el-dialog__headerbtn{
    top: 12px;
  }
  /deep/ .box > .el-dialog > .el-dialog__header > .el-dialog__headerbtn > i{
    font-size: 18px;
    font-weight: bolder;
  }
  /*****************第一层弹窗内容*****************/
  /deep/ .box > .el-dialog > .el-dialog__body{
    padding: 1px 0 0 10px ;
    height: 300px;
    line-height: 30px;
    margin-top: 20px;
    margin-bottom: 20px;
  }
  /deep/ .box > .el-dialog > .el-dialog__body > .el-form > .el-form-item{
    margin-bottom: 0;
  }
  /deep/ .box > .el-dialog > .el-dialog__body > .el-form > .el-form-item > .el-form-item__label{
    color: #69727E;
    font-weight: normal;
  }
  /deep/ .box > .el-dialog > .el-dialog__body > .el-form > .el-form-item > .el-form-item__content > .el-input > .el-input__inner{
    width: 610px;
    height: 30px;
  }
  /*****************第一层弹窗底部*****************/
  /deep/ .box > .el-dialog > .el-dialog__footer{
    border-top: 1px solid #e3e6ee;
  }
  /*****************底部按钮*****************/
  /deep/ .dialog-footer{
    width: 100%;
    /*padding-top: 8px;*/
  }
  /deep/ .dialog-footer > .el-button{
    width: 80px;
    height: 30px;
    padding: 0;
  }
  /deep/ .el-input__inner {
    -webkit-appearance: none;
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 30px;
    line-height: 30px;
    outline: 0;
    padding: 0 17px;
    -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
  }
  .footerPage{
    float: right;
    right:20px;
    position: relative;
  }
</style>
